<script>
import { reactive, toRefs } from "vue";
import axios from "axios";
import { useRouter, useRoute } from "vue-router";
import { getSessionStorage } from "@/common";
import Footer from "@/components/Footer.vue";
export default {
    setup() {
        //实例化
        const router = useRouter()
        const route = useRoute()

        const state = reactive({
            setmealArr: []
        })

        loadSetmealData()

        function loadSetmealData() {
            console.log("hpId:"+route.query.hpId)
            //1.获取当前用户的性别

            //2.与服务端交互，获取套餐列表数据
            axios.post('/api/setmeal/listByType', { type: getSessionStorage('user').sex }).then((response) => {
                console.log(response.data)
                let arr = response.data.data  //定义一个临时数组
                for(let i=0; i<arr.length;i++){
                    arr[i].isShow = false   //用来控制元素显示或隐藏
                }
                state.setmealArr = arr
               
            }).catch((error) => {
                console.log(error)
            })
            //3.把数据展示到页面

        }

        function showOrhide(index){
            state.setmealArr[index].isShow = !state.setmealArr[index].isShow; // 切换对应套餐的状态
        }

        function toSelectdate(smId){
            router.push({ path: '/selectdate', query: { hpId: route.query.hpId,smId: smId } })
        }


        return { //把数据和函数暴露出去
            ...toRefs(state),
            loadSetmealData,
            showOrhide,
            toSelectdate
        }
    },
    components: {
        Footer
    }
}
</script>



<template>
    <!-- 总容器 -->
    <div class="wrapper">
        <header>
            <i class="fa fa-angle-left" onclick="history.go(-1)"></i>
            <p>选择体检套餐</p>
            <div></div>
        </header>
        <div class="top-ban"></div>

        <ul class="setmeal">
            <li v-for="(setmeal, index) in setmealArr" :key="setmeal.smId">
                <div class="item">
                    <div class="item-left" @click="toSelectdate(setmeal.smId)">
                        <h3>{{ setmeal.type == 1 ? "男士套餐" : "女士套餐" }}</h3>
                        <p>{{ setmeal.name }}
                            <a>￥{{ setmeal.price }}</a>
                        </p>

                    </div>
                    <div class="item-right" @click="showOrhide(index)">
                        <p>详情</p>
                        <i class="fa" :class="setmeal.isShow ? 'fa-angle-down' : 'fa-angle-up'"></i>
                    </div>
                </div>
                <div class="item-content"  v-if="setmeal.isShow">
                    <table>
                        <thead>
                            <tr>
                                <th>检查项目</th>
                                <th>检查内容</th>
                                <th>检查意义</th>
                            </tr>
                        </thead>
                        <tr v-for="checkItem in setmeal.checkItemList" :key="checkItem.ciId">
                            <td>{{ checkItem.ciName }}</td>
                            <td>{{ checkItem.ciContent }}</td>
                            <td>{{ checkItem.meaning }}</td>
                        </tr>

                    </table>
                </div>
            </li>

        </ul>

        <div class="bottom-ban"></div>
        <Footer></Footer>
    </div>
</template>



<style scoped>
/*********************** 总容器 ***********************/
.wrapper {
    width: 100%;
    height: 100%;
    background-color: #F9F9F9;
}

/*********************** header ***********************/
header {
    width: 100%;
    height: 15.7vw;
    background-color: #FFF;

    position: fixed;
    left: 0;
    top: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    box-sizing: border-box;
    padding: 0 3.6vw;
}

header .fa {
    font-size: 8vw;
}

/*********************** common样式 ***********************/
.top-ban {
    width: 100%;
    height: 15.7vw;
}

.bottom-ban {
    width: 100%;
    height: 14.2vw;
}

/*********************** setmeal ***********************/
.setmeal {
    width: 100%;
    margin-top: 10vw;
}

.setmeal li {
    width: 92.8vw;
    margin: 0 auto;
    border: solid 1px #EEE;
    border-radius: 1vw;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, .08);
    background-color: #FFF;
    margin-bottom: 3.6vw;
}

.setmeal li .item {
    width: 100%;
    height: 20vw;
    color: #555;

    display: flex;
    align-items: center;
}

.setmeal li .item .item-left {
    flex: 0 0 72vw;
    height: 20vw;
    border-right: solid 1px #EEE;
    box-sizing: border-box;
    padding-left: 12vw;

    display: flex;
    flex-direction: column;
    justify-content: center;

    user-select: none;
    cursor: pointer;
}

.setmeal li .item .item-left h3 {
    font-size: 4.3vw;
    font-weight: 600;
}

.setmeal li .item .item-left p {
    font-size: 4vw;
    margin-top: 1vw;
}

.setmeal li .item .item-left a {
    font-size: 4vw;
    margin-top: 1vw;
    margin-left: 17vw;
    color: goldenrod;
}

.setmeal li .item .item-right {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;

    user-select: none;
    cursor: pointer;
}

.setmeal li .item .item-right p {
    font-size: 4vw;
    margin-right: 2vw;
}

.setmeal li .item-content {
    /*display: none;*/
    width: 100%;
    background-color: #FFF;
}

.setmeal li .item-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 4vw;
    color: #555;
}

.setmeal li .item-content table tr {
    display: flex;
}

.setmeal li .item-content table tr td,
.setmeal li .item-content table tr th {
    flex: 1;
}

.setmeal li .item-content table tr th {
    text-align: center;
    background-color: #EEE;
    height: 10vw;
    line-height: 10vw;
}

.setmeal li .item-content table tr td {
    border: solid 1px #EFEFEF;
    box-sizing: border-box;
    padding: 2vw;
}
</style>